package com.k1998.mybatis.service.impl;

import com.k1998.mybatis.bean.Student;
import com.k1998.mybatis.dao.IStudentDao;
import com.k1998.mybatis.service.StudentService;
import com.k1998.mybatis.utils.HashMapUtils;
import com.k1998.mybatis.utils.QueryInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("StudentService")
public class StudentServiceImpl implements StudentService {
    @Autowired
    private IStudentDao iStudentDao;

    @Override
    public String getAllStudents(QueryInfo queryInfo) {
        int numbers = iStudentDao.getStudentCounts("%"+queryInfo.getQuery()+"%");// 查询到的结果数量
        int pageStart = (queryInfo.getPageNum()-1)*queryInfo.getPageSize(); // 第几条数据开始
        List<Student> students = iStudentDao.findAll("%"+queryInfo.getQuery()+"%",pageStart,queryInfo.getPageSize());
        return HashMapUtils.toHashMap(numbers,students);
    }
}
